#include "packageeditor.h"
#include "ui_packageeditor.h"

#include "uml/umldiritem.h"

PackageEditor::PackageEditor(UmlDirItem *dirItem) :
    ui(new Ui::PackageEditor),
    _dirItem(dirItem)
{
    ui->setupUi(this);

    this->ui->packageNameLineEdit->setText(this->_dirItem->name());

    QObject::connect(this->ui->pushButtonSave, SIGNAL(clicked()), this, SLOT(save()));
    QObject::connect(this->ui->pushButtonCancel, SIGNAL(clicked()), this, SLOT(cancel()));
}

PackageEditor::~PackageEditor()
{
    delete ui;
}

void PackageEditor::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void PackageEditor::save()
{
    this->_dirItem->setText(this->ui->packageNameLineEdit->text());

    this->done(QDialog::Accepted);
}

void PackageEditor::cancel()
{
    this->done(QDialog::Rejected);
}
